package com.traffic.api.filter;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.traffic.api.exception.ApiBizException;

/**
 * 请求参数验证
 * @author Guoxing
 *
 */
public class ApiParamsFactoryFilter {

	public static final void check(Map<String, Object> params) {

		if ((params.get("phoneNo") == null) || ("".equals(params.get("phoneNo")))) {
			throw new ApiBizException(new Throwable("手机号码不能为空"));
		}
		if (isMobileNO((String) params.get("phoneNo"))) {
			throw new ApiBizException(new Throwable("手机号码不正确"));
		}
		if ((params.get("productId") == null) || ("".equals(params.get("productId")))) {
			throw new ApiBizException(new Throwable("产品不能为空"));
		}
		if ((params.get("cstmOrderNo") == null) || ("".equals(params.get("cstmOrderNo")))) {
			throw new ApiBizException(new Throwable("流水号不能为空"));
		}

	}

	public static boolean isMobileNO(String mobiles) {
		Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0-9])|(17[0-9]))\\d{8}$");
		Matcher m = p.matcher(mobiles);
		return !m.matches();
	}

}